package com.dhp.bkOjquestionservice.rabbitMQ;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 消息队列生产者
 */
@Component
@Slf4j
public class MessageProducer {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送消息
     * @param exchange 交换机
     * @param routingKey
     * @param message 消息
     */
    public void sendMessage(String exchange , String routingKey , String message){
        if (StringUtils.isAnyEmpty(exchange , routingKey , message)){
            log.info("必要参数为空");
        }

        rabbitTemplate.convertAndSend(exchange , routingKey , message);
    }
}
